<!--
 * @Author: xuwejie 1529315455@qq.com
 * @Date: 2023-08-28 11:38:43
 * @LastEditors: xuwejie 1529315455@qq.com
 * @LastEditTime: 2023-08-29 13:59:41
 * @FilePath: \cdj-jyt_school-vue\src\views\shop\afterSale.vue
 * @Description: 用于富文本页面编写
-->
<template>
  <div class="page">
    <Editor
      api-key="vl7byj8kh7hyvvi6o7137s7khcpfsp762987dlnbcd93u37a"
      v-model="content"
      :init="init"
    ></Editor>
    <div class="bottom">
      <el-button class="btn" type="primary" @click="submit()" v-repeatClick
        >保存</el-button
      >
    </div>
  </div>
</template>

<script>
import Editor from "@tinymce/tinymce-vue";
import init from "./init";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { partnerNotice_index, partnerNotice_save } from "@/api/shop/shop";
// 通过type判断富文本的类型
let type = null;
export default {
  data() {
    return {
      content: "",
      // 富文本
      init,
    };
  },
  beforeRouteEnter(to, from, next) {
    let txt = to.meta.title;
    if (txt == "关于我们") {
      type = "1";
    } else if (txt == "服务条款") {
      type = "2";
    } else if (txt == "售后规则") {
      type = "3";
    } else if (txt == "注册协议") {
      type = "4";
    }
    next();
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      let data = Object.assign(
        { type: type },
        apiUrl().name
      );
      partnerNotice_index(data).then((res) => {
        if (res.errcode == 0) {
          this.content = res.data.content;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    submit() {
      let data = Object.assign(
        { type: type, content: this.content },
        apiUrl().name
      );
      partnerNotice_save(data).then((res) => {
        if (res.errcode == 0) {
          this.$message.success("保存成功");
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
  },
  components: {
    Editor,
  },
};
</script>

<style lang="scss" scoped>
.page {
  width: 100%;
  height: 100vh;
  .bottom {
    background: #fff;
    box-shadow: 10px 10px 10px #eee;
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    padding: 40px 30px;
    .btn {
      width: 120px;
    }
  }
}
</style>